package com.wwz.frame.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description 拦截器跨域配置
 * @Author wwz
 * @Date 2019/06/25
 * @Param
 * @Return
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    /**
     * cors跨域配置
     * 验证  http://127.0.0.1:8001/frame/file/cors.html
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //添加映射路径
        registry.addMapping("/**")
                //放行哪些原始域
                .allowedOrigins("*")
                //是否发送Cookie信息
                .allowCredentials(true)
                //放行哪些原始域(请求方式)
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                //放行哪些原始域(头部信息)
                .allowedHeaders("*")
                //暴露哪些头部信息（因为跨域访问默认不能获取全部头部信息）
                .exposedHeaders("Header1", "Header2");

    }
    /**
     * 资源映射   http://127.0.0.1:8080/frame/file/login.html访问resources/file/login.html页面
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/web/**").addResourceLocations("classpath:/web/");
    }
}
